package TestThread;
class Count{
    public int count;
    synchronized public void add() {
            count++;
    }
}
public class demo9 {
    public static void main(String[] args) throws InterruptedException {
        Count count = new Count();
        Thread thread1 =new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                count.add();
            }
        });
        Thread thread2 =new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                synchronized (count) {
                    synchronized (count) {
                        count.add();
                    }
                }
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(count.count);
    }
}
